package alogrithm.structure;

import java.util.Stack;

public class TreeNode {
	private Object value;
	private TreeNode leftChild;
	private TreeNode rightChild;
	
	public TreeNode()
	{}
	
	public TreeNode(Object _value)
	{
		value=_value;
	}
	
	public TreeNode(Object _value,TreeNode _left,TreeNode _right)
	{
		value=_value;
		leftChild=_left;
		rightChild=_right;
	}
	

	public Object getValue() {
		return value;
	}
	public void setValue(Object value) {
		this.value = value;
	}
	public TreeNode getLeftChild() {
		return leftChild;
	}
	public void setLeftChild(TreeNode leftChild) {
		this.leftChild = leftChild;
	}
	public TreeNode getRightChild() {
		return rightChild;
	}
	public void setRightChild(TreeNode rightChild) {
		this.rightChild = rightChild;
	}
	
	public String toString()
	{
		return value.toString();
	}
	
	public static void middleOrderUsingRecursive(TreeNode node)
	{
		if(node!=null)
		{
			middleOrderUsingRecursive(node.getLeftChild());
			System.out.print(node+"\t");
			middleOrderUsingRecursive(node.getRightChild());
		}
	}
	
	public static void middleOrderWithoutRecursive(TreeNode node)
	{
		Stack<TreeNode> s=new Stack<TreeNode>();
		if(node==null)return;
		while((!s.isEmpty())||node!=null)
		{
			while(node!=null)
			{
				s.push(node);
				node=node.getLeftChild();		
			}
			node=s.pop();
			System.out.print(node+"\t");
			node=node.getRightChild();
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
